//
// Created by PC on 2024/4/15.
//


#include <iostream>
#include <vector>

using namespace std;

struct Node
{
    int v;
    Node *next;
};

void printLinkedList(Node *h)
{
    Node *cur = h->next;
    while (cur)
    {
        cout << cur->v << ' ';
        cur = cur->next;
    }
    cout << endl;
}
Node * build(vector<int> v)
{
    Node *head = new Node();
    Node *cur = head;
    for (int i = 0; i < v.size(); ++i)
    {
//        cur->next=new Node{l[i], nullptr};
        cur->next = new Node();
        cur->next->v = v[i];
        cur = cur->next;
    }
    return head;
}

Node * reverse01(Node *h)
{
    Node *cur=nullptr;
    Node *pre = nullptr;
    while (h)
    {
        cur=h->next;
        h->next=pre;
        pre=h;
        h=cur;
    }
    h = new Node{0,pre};
    return h;
}

int main()
{
    vector<int> v{1,2,3,4,5,6,7,8};
    Node *h = build(v);
    printLinkedList(h);
    h = reverse01(h->next);
    printLinkedList(h);
    return 0;
}